<div class="maintop">
    当前位置：商品分类属性
    <a href="javascript:;" action="<?=$basepath?>_add" class="mainFrame button icon-plus">添加属性</a>
    <a href="javascript:;" action="<?=$basepath?>?<?=$this->page_url($searchdata['page_current'],$page_url)?>" class="mainFrame button">刷新</a>
    <? if(ISDEBUG){ ?>
        <a href="javascript:$('.debuginfo').toggle();" class="button">调试信息</a>
    <? } ?>
</div>
<div class="main-search">
    <table width="100%">

        <tbody><tr>
            <td>
                <form action="<?=$basepath?>" id="brandsSearch" method="get" target="ajax" dataType="html" onajax="beforeSearchForm" call="searchForm" container="#iframe" isLoad="true">
                <select id="categoryid" name="categoryid">
                    <option value="0"<?=(intval($searchdata['categoryid'])==0 ?' selected="selected"':'') ?>>全部分类</option>
                    <? foreach($parent_category as $v){ ?>
                        <option value="<?=$v['id']?>"<?=(intval($searchdata['categoryid'])==intval($v['id']) ?' selected="selected"':'') ?>><?=$v['title']?></option>
                    <? } ?>
                </select>
                <select id="categorysubid" name="categorysubid">
                    <option value="" selected="selected">全部子类</option>
                </select>
                <input type="text" id="sKey" name="sKey" class="int" placeholder="搜索关键字">
                    每页：
                    <select id="ps" name="ps">
                        <option value="12" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 12) echo 'selected';?> >12</option>
                        <option value="20" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 20) echo 'selected';?> >20</option>
                        <option value="30" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 30) echo 'selected';?> >30</option>
                        <option value="50" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 50) echo 'selected';?> >50</option>
                        <option value="100" <?php if($this->existsKeyInArray('ps',$searchdata,'N',$this->pagesize) == 100) echo 'selected';?> >100</option>
                    </select>
                    <input type="submit" value="搜索" class="upbutton">
                    <input action="<?=$basepath?>_delete_list" type="button" id="deleteSelectId" value="删除选择" class="upbutton">
                </form>
            </td>
        </tr>
        </tbody>

    </table>
</div>
<div id="mainbody">
    <table width="100%" class="tablist">
        <tr class="trbg"><th><input id="selectAllid" type="checkbox" value="1" /></th><th>名称</th><th>字段名<th>默认值</th><th>样式</th><th>商品分类</th><th>快捷搜索</th><th>排序</th><th width="90">操作</th></tr>
        <? foreach($datas as $v){ ?>
            <tr>
                <td width="30"><input type="checkbox" name="selectValue" value="<?=$v['id']?>" /></td>
                <td><?=$v['title']?></td>
                <td>f_<?=$v['categoryid']?><?=$v['categorysubid']?></td>
                <td><?=$v['defaultvalue']?></td>
                <td><?=$this->input_type[$v['defaultvaluestyle']] ?></td>
                <td><?=$v['categoryid'] ?><?=$v['categorysubid']?></td>
                <td><a href="<?=$basepath?>_state?id=<?=$v['id']?>&state=<?=$v['state']?>" target="ajax" func="loadpage" class="upbutton"><?=($v['search']?'启用':'禁用')?></a></td>
                <td><?=$v['sort']?></td>
                <td>
                    <a action="<?=$basepath?>_delete?id=<?=$v['id']?>&csid=<?=$v['categorysubid']?>" title="删除" class="mainFrame button icon-trash-2" href="javascript:;"></a>
                    <a action="<?=$basepath?>_edit?id=<?=$v['id']?>" title="编辑" class="mainFrame button icon-edit" href="javascript:;"></a>
                </td>
            </tr>
        <? } ?>
    </table>
    <? require VIEW.'/page.view.php' ?>
</div>
<script type="text/javascript">
function beforeSearchForm(){
    var _key = this.sKey.value;
    if(_key.length<=0){
        //throw '搜索关键字不能为空';
    }
}
function searchForm(self, _html, data){
    $("#iframe").html(_html);
}
	$(document).ready(function(){
		var _default_sub_html = '';
		<? 
		$_de_sub = '<option value="0" '.(intval($searchdata['categorysubid'])==0 ? ' selected="selected"':'').'>请选择</option>';
		 if($categorysub && count($categorysub)){
			foreach($categorysub as $k=>$v){
				$_de_sub .= '<option value="'.$k.'" '.($k==intval($searchdata['categorysubid']) ? ' selected="selected"':'').'>'.$v.'</option>';
			}
		}
		echo '_default_sub_html = \''.$_de_sub.'\';';									   
		?>
		if(_default_sub_html!==''){
			$('#categorysubid').html(_default_sub_html);
		}else{
			$('#categorysubid').hide();
		}
		$("#categoryid").change(function(){
			var _vid = $(this).val();
			var _subcategory = $("#categorysubid");
			if(parseInt(_vid)>0){
				$('#categorysubid').fadeIn(500);
				jsondata({
					url : '/product/attribute_search_select',
					data : { id : _vid},
					type : 'GET',
					callback : function(data, textStatus, xhr){
						var _html = '<option value="0" selected="selected">请选择</option>';
                		_subcategory.html('');
						$.each(data,function(index,val){
							_html += '<option value="'+val['id']+'">'+val['title']+'</option>';
						});
                		_subcategory.html(_html);
					}
				});
			}else{
				$('#categorysubid').fadeOut(500);
				_subcategory.html('<option value="0" selected="selected">请选择</option>');
			}
		});
	});
</script>
